#ifndef OS_QUEUE_H
#define OS_QUEUE_H

#include "os_def.h"
#include "os_event.h"

/**
 * 消息队列
 */
typedef struct _os_queue_t {
    uint16_t msg_max;                    // 最大消息数量
    os_event_t read_event;          // 写事件结构
    os_event_t write_event;         // 读事件结构
    uint16_t msg_cnt;               // 当前消息数量
    uint16_t msg_size;              // 消息块的大小
    uint16_t total_size;            // 总的消息大小
    uint16_t read, write;           // 读写索引
    uint8_t * pool;               // 消息缓存
}os_queue_t;

#define OS_QUEUE_RELEASE_NORMAL     (0 << 0)    // 普通发送方式
#define OS_QUEUE_RELEASE_URGENT      (1 << 0)    // 消息发送至头部

os_err_t os_queue_init (os_queue_t * queue, void * msg_buf, uint16_t msg_size, uint16_t msg_cnt);
os_err_t os_queue_uninit(os_queue_t * queue);
os_queue_t * os_queue_create (uint16_t msg_size, uint16_t msg_cnt);
os_err_t os_queue_free (os_queue_t * queue);
uint16_t os_queue_msg_cnt (os_queue_t * queue);
uint16_t os_queue_free_cnt (os_queue_t * queue);
uint16_t os_queue_read_task_cnt(os_queue_t * queue);
uint16_t os_queue_write_task_cnt (os_queue_t * queue);
os_err_t os_queue_clear (os_queue_t * queue);
os_err_t os_queue_read (os_queue_t * queue, int ms, int opt, void * msg);
os_err_t os_queue_write (os_queue_t * queue, int ms, int opt, void * msg);

#endif /* TMBOX_H */ 
